/*
 * CAudioPresenter.h
 *
 *  Created on: Sep 6, 2011
 *      Author: welcome
 */

#ifndef CAUDIOPRESENTER_H_
#define CAUDIOPRESENTER_H_

#include <SLES/OpenSLES.h>
#include <KD/kd.h>
#include "CMediaSound.h"

namespace GGEngine {

class CAudioPresenter {
public:
	CAudioPresenter();
	virtual ~CAudioPresenter();

	static int initializeEngine(); /* should be called only once */
	static void releaseEngine(); /* should be called only once */

	static void setOutputMute(bool mute);
	static bool getOutputMute();

private:
	static int createOutputMix();
	static void disposeOutputMix();

	static SLObjectItf sl;
	static SLEngineItf eng;
	static SLObjectItf outputMix;

	static SLVolumeItf out_vol;
private:
	SLint32 createPCMPlayer();
	void createPlayer();
public:
	void setSound(CMediaSound* _sound);

	CMediaSound* getMediaSound();

	void releasePlayResource();

	void play();
	void play(int time);
	void pause();
	void stop();
	int getCurrentTime();
	int getTotalTime();
	void restart();

	SLuint32 getPlayState();
	void setVolume(int _volume);
	int getVolume();
	void setLoop(bool _loopFlag);
	bool isLoop();
	void setCurrentTime(int time);

	void setMute(bool mute);
	bool getMute();

private:
	SLObjectItf player;
	SLPlayItf playItf;
	SLVolumeItf vol;
	SLSeekItf seek;

	SLmillisecond dur;
	CMediaSound* sound;

	int volume;
	bool loopFlag;
};

} /* namespace GGEngine */
#endif /* CAUDIOPRESENTER_H_ */
